package com.ycfmedical.bed.serverdata;

/**
 * Created by Administrator on 2017-04-12.
 */

import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.R.string;
import android.os.CountDownTimer;
import android.util.Log;

import cn.droidlover.xdroidmvp.kit.Kits;
import cn.droidlover.xdroidmvp.log.XLog;

public class DBUtil {
    private ArrayList<String> arrayList = new ArrayList<String>();
    private ArrayList<String> brrayList = new ArrayList<String>();
    private ArrayList<String> crrayList = new ArrayList<String>();
    private HttpConnSoap Soap = new HttpConnSoap();
    public static Connection getConnection() {
        Connection con = null;
        try {}
        catch (Exception e) {}
        return con;
    }
    public void cleanthread()
    {
        arrayList.clear();
        Soap.GetWebServre("clean",arrayList,arrayList);
    }

    /**
     * 获取历史体征数据
     *
     * @return
     */
    public List<HashMap<String, String>> get_data(String  time,String e_id) {
        List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

        clear();
        brrayList.add(time);
        brrayList.add(e_id);
        arrayList.add("time");
        arrayList.add("e_id");
        crrayList = Soap.GetWebServre("get_data", arrayList, brrayList);
        if(crrayList != null && crrayList.size() != 1)
        {
            for (int j = 0; j < crrayList.size(); j += 6) {
                HashMap<String, String> hashMap = new HashMap<String, String>();
                hashMap.put("时间", crrayList.get(j));
                hashMap.put("用户ID", crrayList.get(j + 1));
                hashMap.put("心率", crrayList.get(j + 2));
                hashMap.put("呼吸", crrayList.get(j + 3));
                hashMap.put("体动", crrayList.get(j + 4));
                hashMap.put("状态", crrayList.get(j + 5));
                list.add(hashMap);
            }
        }
        Log.e(" get list ==", ""+list);
        return list;
    }
    //保存生命体征数据
    public String save_tizheng(String time,String e_id,String HeartRate,String breathing,String attitude,String bedstatus)
    {

        String result ="0";
        clear();
        brrayList.add(time);
        brrayList.add(e_id);
        brrayList.add(HeartRate);
        brrayList.add(breathing);
        brrayList.add(attitude);
        brrayList.add(bedstatus);

        arrayList.add("time");
        arrayList.add("e_id");
        arrayList.add("hr");
        arrayList.add("breathing");
        arrayList.add("attitude");
        arrayList.add("bedstatus");

        try
        {
            XLog.e("SJHdata","正在存贮数据");
            Soap.GetWebServre("save_tizheng", arrayList, brrayList);
                result ="1";
        }
        catch(Exception e)
        {

        }
        return result;
    }
    //获取一键体位指令
    public String get_tiwei(String tiwei,String e_id) {

        String result ="0";
        clear();
        brrayList.add(tiwei);
        brrayList.add(e_id);

        arrayList.add("tiwei");
        arrayList.add("e_id");
        crrayList = Soap.GetWebServre("get_tiwei", arrayList, brrayList);
        if (crrayList!=null && !crrayList.isEmpty() )
        {
            result =crrayList.get(0).toString();
        }
        return result;
    }
    //更新一键体位指令
    public String update_tiwei(String data,String  tiwei,String e_id) {

        String result ="0";
        clear();
        brrayList.add(data);
        brrayList.add(tiwei);
        brrayList.add(e_id);

        arrayList.add("data");
        arrayList.add("tiwei");
        arrayList.add("e_id");

        crrayList = Soap.GetWebServre("update_tiwei", arrayList, brrayList);
        if (crrayList!=null && !crrayList.isEmpty())
        {
            result =crrayList.get(0).toString();
        }
        return result;
    }

    /**
     * 获取体温数据信息
     *
     * @return
     */
    public List<HashMap<String, String>> get_temp_data(String  time,String e_id) {
        List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

        clear();
        brrayList.add(time);
        brrayList.add(e_id);
        arrayList.add("time");
        arrayList.add("e_id");
        crrayList = Soap.GetWebServre("get_temp_data", arrayList, brrayList);
        if(crrayList != null &&crrayList.size() != 1)
        {
            for (int j = 0; j < crrayList.size(); j += 6) {
                HashMap<String, String> hashMap = new HashMap<String, String>();
                hashMap.put("时间", crrayList.get(j));
                hashMap.put("温度", crrayList.get(j + 1));
                hashMap.put("使用设备", crrayList.get(j + 2));
                list.add(hashMap);
            }
        }
        Log.e(" get list ==", ""+list);
        return list;
    }

    /**
     * 获取体重数据信息
     *
     * @return
     */
    public List<HashMap<String, String>> get_weight_data(String  time,String e_id) {
        List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

        clear();
        brrayList.add(time);
        brrayList.add(e_id);
        arrayList.add("time");
        arrayList.add("e_id");
        crrayList = Soap.GetWebServre("get_weight_data", arrayList, brrayList);
        if(crrayList != null && crrayList.size() != 1)
        {
            for (int j = 0; j < crrayList.size(); j += 6) {
                HashMap<String, String> hashMap = new HashMap<String, String>();
                hashMap.put("时间", crrayList.get(j));
                hashMap.put("体重", crrayList.get(j + 1));
                hashMap.put("使用设备", crrayList.get(j + 2));
                list.add(hashMap);
            }
        }
        Log.e(" get list ==", ""+list);
        return list;
    }
    //保存体温体重
    public String save_twtz(String e_id,String value,String mac) {

        String result ="0";
        clear();
        brrayList.add(e_id);
        brrayList.add(value);
        brrayList.add(mac);

        arrayList.add("e_id");
        arrayList.add("value");
        arrayList.add("mac");
        if (crrayList!=null && !crrayList.isEmpty()) {
            crrayList = Soap.GetWebServre("save_twtz", arrayList, brrayList);
            result = crrayList.get(0).toString();
        }
        return result;
    }
    private void clear()
    {
        if (arrayList != null)
        {
            arrayList.clear();
        }
        if (brrayList != null)
        {
            brrayList.clear();
        }
        if (crrayList != null)
        {
            crrayList.clear();
        }
    }

    private static class staticClassLazy
    {
        private static DBUtil dbUtil=new DBUtil();
    }
    private DBUtil(){

    }
    public static DBUtil getInstance()
    {
        return staticClassLazy.dbUtil;
    }
}

